package anna.lopez.mora;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.TextView;

public class Jumpview extends Activity{
	public Handler handler;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gamejump);
		GV.Instancies.jumpview = this;
		GV.puntuacio.mort = false;
		GV.Instancies.gamejump = (Gamejump) findViewById(R.id.gamejumpview);
		PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		GV.Screen.wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GameOnLock");
		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				if(msg.what == 0) update();
				else if (msg.what == 1) muertejugador();
			}
		};
	}
	
	public void update() {
		TextView nlives = (TextView) findViewById(R.id.numvid);
		nlives.setText(String.valueOf(GV.puntuacio.vides));
	}
	
	public void muertejugador() {
		Intent i = new Intent("anna.lopez.mora.GAMEOVERVIEW");
		startActivity(i);
		finish();
	}

	@Override
	protected void onPause() {
		GV.Instancies.gamejump.stop();
		GV.Screen.wl.release();
		super.onPause();
	}

	@Override
	protected void onResume() {
		GV.Screen.metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(GV.Screen.metrics);
		GV.Instancies.gamejump.start();
		GV.Screen.wl.acquire();
		super.onResume();
	}
	@Override
	public void onBackPressed() {
		finish();
		//activity transition animation
		super.onBackPressed();
	}
}
